package com.example.owner.lettery1.adapter

import android.graphics.Color
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.example.owner.lettery1.R
import com.example.owner.lettery1.modlus.Ball
import com.example.owner.lettery1.utils.ResUtil


class BallAdapter(private val balls: List<Ball>, private val typeId : String) : RecyclerView.Adapter<BallAdapter.BallHolder>() {

    private var ballNumberView : TextView? = null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BallHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_ball, parent, false)
        return BallHolder(itemView)
    }

    override fun getItemCount(): Int = balls.size

    override fun onBindViewHolder(holder: BallHolder, position: Int) {
        holder.bindView(balls[position])
    }

  inner  class BallHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        fun bindView(ball: Ball) {
            ballNumberView = itemView.findViewById(R.id.ballNumberView)
            when (typeId) {
                "11" -> {
                    ballNumberView!!.setBackgroundResource(R.color._tran)
                    ballNumberView!!.setTextColor(Color.WHITE)
                    ballNumberView!!.setPadding(4, 4, 4, 4)
                }
                "16" -> {
                    ballNumberView!!.setBackgroundResource(R.color.green)
                    ballNumberView!!.setPadding(8, 8, 8, 8)
                }
                "18" -> {
                    ballNumberView!!.setBackgroundResource(R.color.tran)
                    ballNumberView!!.setTextColor(Color.RED)
                    ballNumberView!!.textSize = ResUtil.getDimension(R.dimen.text_min)
                    ballNumberView!!.setPadding(8, 8, 8, 8)
                }
                "19" -> {
                    ballNumberView!!.setBackgroundResource(R.color.tab_red)
                    ballNumberView!!.setTextColor(Color.WHITE)
                    ballNumberView!!.setPadding(4, 4, 4, 4)
                }
                else -> {
                    ballNumberView!!.isSelected = ball.isSelector
                    ballNumberView!!.setBackgroundResource(R.drawable.ball_selector  )
                }
            }
            ballNumberView!!.text = ball.number
        }
    }
}